package net.funtip.ormgenerator.model;

import java.util.ArrayList;
import java.util.List;

public class UniqueConstraint {

	private Entity entity;
	private List<Attribute> attributes;

	public UniqueConstraint(Entity entity) {
		this.entity = entity;
		this.attributes = new ArrayList<Attribute>();
		entity.addUniqueConstraint(this);
	}
	
	public List<Attribute> getAttributes() {
		return attributes;
	}

	public void addAttribute(Attribute a) {
		this.attributes.add(a);
	}

	public Entity getEntity() {
		return entity;
	}
	
	public String getName() {
		StringBuffer sbuf = new StringBuffer();
		sbuf.append("UK_");
		sbuf.append(entity.getName().toUpperCase());
		for (Attribute a: getAttributes()) {
			sbuf.append("_").append(a.getName().toUpperCase());
		}
		return sbuf.toString();
	}
}
